﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MedicinaMuncii.Entities;
using MedicinaMuncii.BL.Contracts;
using MedicinaMuncii.IoC;

namespace MedicinaMuncii.UI.Mvc.Controllers
{
    public class MedicalAdviceController : BaseController
    {
        IMedicalAdviceService medicalAdviceService;

       #region Constructor
        public MedicalAdviceController()
        {
            medicalAdviceService = IoCWorker.Resolve<IMedicalAdviceService>();
        }
        #endregion Constructor

        public ActionResult Index()
        {
            IList<MedicalAdvice> companies = medicalAdviceService.GetAll();
            return View(companies);
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(MedicalAdvice medicalAdvice)
        {
            try
            {
                medicalAdviceService.Add(medicalAdvice);
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return View();
            }
        }

        public ActionResult Edit(int id)
        {
            MedicalAdvice medicalAdvice = medicalAdviceService.GetByID(ma => ma.ID == id);
            return View(medicalAdvice);
        }

        [HttpPost]
        public ActionResult Edit(MedicalAdvice medicalAdvice)
        {
            try
            {
                medicalAdviceService.Update(medicalAdvice);
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return View();
            }
        }

        public ActionResult Delete(int id)
        {
            medicalAdviceService.Delete(ma => ma.ID == id);
            return RedirectToAction("Index");
        }
    }
}
